<template>
  <el-aside :width="$store.state.isCollapse ? '180px' : '60px'">
    <!-- 动画效果调整
    :collapse-transition="false" -->
    <el-menu
      class="el-menu-vertical-demo"
      text-color="#fff"
      background-color="#545c64"
      :collapse="!$store.state.isCollapse"
      :collapse-transition="false"
    >
      <h3 v-text="$store.state.isCollapse ? longTitle : littleTitle"></h3>
      <el-menu-item
        :index="item.path"
        v-for="item in noClildren()"
        :key="item.path"
        @click="clickMenu(item)"
      >
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.label }}</span>
      </el-menu-item>
      <el-sub-menu
        :index="item.label"
        v-for="item in hasClildren()"
        :key="item.path"
      >
        <template #title>
          <component class="icons" :is="item.icon"></component>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="subItem.path"
            v-for="(subItem, subIndex) in item.children"
            :key="subIndex"
            @click="clickMenu(subItem)"
          >
            <component class="icons" :is="subItem.icon"></component>
            <span>{{ subItem.label }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script>
import { useRouter } from "vue-router";
import { useStore } from "vuex";
//import menuList from "../router/menu/menu.js";
export default {
  name: "CommonAside",
  setup() {
    const store = useStore();
    const asyncList = store.state.menu;
    let list = asyncList.items;
    let longTitle = asyncList.longTitle;
    let littleTitle = asyncList.littleTitle;
    const router = useRouter();
    const noClildren = () => {
      return list.filter((item) => !item.children);
    };
    const hasClildren = () => {
      return list.filter((item) => item.children);
    };
    const clickMenu = (item) => {
      router.push({
        name: item.name,
      });
      store.commit("selectMenu", item);
    };
    return {
      longTitle,
      littleTitle,
      noClildren,
      hasClildren,
      clickMenu,
    };
  },
};
</script>

<style lang="less" scoped>
.icons {
  width: 16px;
  height: 16px;
}
.el-menu {
  border-right: none;
  height: 100vh;
  h3 {
    line-height: 48px;
    color: #fff;
    text-align: center;
  }
}
</style>
